const element = document.getElementById("notification-badge"); const HERMES_API_URL = window.location.hostname === "ebooks.cpm.org" ? "https://cdp-hermes.cpm.org" : "https://cdp-hermes-test.cpm.org"; function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(";").shift(); } const getUnreadNotifications = async () => { const cookie = getCookie("cpm-sso-token"); try { const notifications = await fetch(HERMES_API_URL + "/api/eworkspace/owner/alerts/thin", { method: "GET", headers: { Authorization: "Bearer " + cookie, }, }); const data = await notifications.json(); if (data.length) element.textContent = data.length; return; } catch (error) { return console.log(error); } }; getUnreadNotifications();